package com.open.yujiakj.controller.system;
import com.open.yujiakj.common.domain.R;
import com.open.yujiakj.core.domain.Menu;
import com.open.yujiakj.core.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.springframework.validation.annotation.Validated;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;




/**
 * @author honglei
 * @version 1.0
 * @time: 2025-5-23 19:22:57
 * @Description 服务实现层 菜单权限表
 */


@RestController
@RequestMapping("/api/menu/")
public class MenuController {


@Autowired
MenuService service;


/**
* 根据id获取详情
*
* @param request
* @param id
* @return
*/
@GetMapping(value = "get")
public R get(HttpServletRequest request, Serializable id) {
return R.ok(service.findById(id));
}

/**
* 分页查询
*
* @return
*/
@RequestMapping(value = "getPage", method = {RequestMethod.GET, RequestMethod.POST})
public R getPage(@RequestBody Map mapReq) {
return R.ok(service.findPage(mapReq));
}


/**
* 普通更新
*
* @param list
* @return
*/
@PostMapping(value = "updateBatch")
public R updateBatch(@RequestBody List<Menu> list) {

    return R.ok(service.editBatch(list));
    }


    /**
    * 新增
    *
    * @param list
    * @return
    */
    @PostMapping(value = "saveBatch")
    public R save(@RequestBody List<Menu> list) throws Exception {
        return R.ok(service.saveBatch(list, 0));
        }


        /**
        * 删除
        *
        * @param request
        * @param id
        * @return
        */
        @PostMapping(value = "del/{id}")
        public R del(HttpServletRequest request, @PathVariable("id") Serializable id) {
        return R.ok(service.removeById(id, 0));
        }

    }
